﻿
(function () {
    appModule.controller('common.views.caseCategorys.createOrEditModal', [
        '$scope', '$uibModalInstance', 'abp.services.app.caseCategory', 'caseCategoryId', 'textAngularManager',
        function ($scope, $uibModalInstance, caseCategoryService, caseCategoryId, textAngularManager) {
            var vm = this;
            vm.saving = false;
            //首先将caseCategory数据设置为null
            vm.caseCategory = null;



            //触发保存方法
            vm.save = function () {
                vm.saving = true;
                caseCategoryService.createOrUpdateCaseCategoryAsync({ caseCategoryEditDto: vm.caseCategory }).then(function () {
                    abp.notify.info(app.localize('SavedSuccessfully'));
                    $uibModalInstance.close();
                }).finally(function () {
                    vm.saving = false;
                });


            };
            //取消关闭页面
            vm.cancel = function () {
                $uibModalInstance.dismiss();
            };

            //初始化页面
            function init() {

                //绑定控件
                caseCategoryService.getCaseCategoryTree().then(function (result) {
                    vm.caseCategoryList = result.data;

                    caseCategoryService.getCaseCategoryForEditAsync({
                        id: caseCategoryId
                    }).then(function (result) {
                        vm.caseCategory = result.data.caseCategory;
                        vm.caseCategory.parentID = vm.caseCategory.parentID + "";
                    });
                });

                //设置下拉为只读
                if (caseCategoryId != null) {
                    vm.disabled = true;
                }

            }
            //执行初始化方法
            init();
        }
    ]);
})();